package com.ljtg.ljtgservice.controller.user;

import com.ljtg.ljtgpojo.dto.OrderPaymentDTO;
import com.ljtg.ljtgpojo.dto.OrdersSubmitDTO;
import com.ljtg.ljtgpojo.vo.OrderPaymentVO;
import com.ljtg.ljtgpojo.vo.OrderSubmitVO;
import com.ljtg.ljtgservice.service.OrderService;
import com.ljtg.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
//@Api(tags = "用户订单相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 用户下单
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户下单，参数为：{}",ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 订单支付
     * @param orderPaymentDTO
     * @return
     * @throws Exception
     */
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrderPaymentDTO orderPaymentDTO) throws Exception{
        log.info("订单支付: {}",orderPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(orderPaymentDTO);
        log.info("生成预支付交易单: {}",orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
}
